#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @Project : chat_model 
# @File    : embedding_server_logic.py
# @IDE     : PyCharm 
# @Author  :ZH
# @Time    : 2025/1/10 13:08
__all__ = ['embedding_server_logic']

from tortoise.expressions import Q

from apps import cruds
from apps.api.v1.embedding_server_api.schema import EmbeddingServerListRequests


class EmbeddingServerLogic:
    def __init__(self):
        self.crud = cruds.embedding_server_crud

    async def embedding_server_list(self, query: EmbeddingServerListRequests):
        skip = (query.page - 1) * query.limit
        query_sql = self.crud.model.filter(is_delete=False)
        if query.name:
            query_sql = query_sql.filter(embedding_name__icontains=query.name)
        count_ = await query_sql.count()
        if count_:
            data = await query_sql.order_by('-id').offset(skip).limit(query.limit).all()
        else:
            data = []
        return count_, data

    async def embedding_server_info(self, embedding_server_id: int):
        return await self.crud.get_one(is_delete=False, id=embedding_server_id)

    async def embedding_server_info_all(self, **kwargs):
        return await self.crud.get_all(**kwargs)


embedding_server_logic = EmbeddingServerLogic()
